#include <stdio.h>
#include <pthread.h>
#include <unistd.h>


pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t mutex2 = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t cond1=PTHREAD_COND_INITIALIZER;
pthread_cond_t cond2=PTHREAD_COND_INITIALIZER;

int num=0;
void *myfunc1(void *arg)
{
	while(1)
	{	
		pthread_cond_wait(&cond1,&mutex1);
		printf("func1: num=%d\n",num++);
	}
}

void *myfunc2(void *argc)
{	
	while(1)
	{
		pthread_cond_wait(&cond2,&mutex2);
		printf("func2:num=%d\n",num++);
	}
}

int main(int argc, const char *argv[])
{
	pthread_t ptid1,ptid2;
	pthread_create(&ptid1,NULL,myfunc1,NULL);
	pthread_create(&ptid2,NULL,myfunc2,NULL);

	pthread_detach(ptid1);
	pthread_detach(ptid2);	
	int choosenum;
	while(1)
	{	
		scanf("%d",&choosenum);
		switch(choosenum)
		{
		case 1:
			pthread_cond_signal(&cond1);
			break;
		case 2:		
			pthread_cond_signal(&cond2);
			break;
		default:	
			break;
		}
	}

	return 0;
}
